-- CALC_BROKEN_LAIR_BONUS

-- 计算残破的巢穴奖励（隐藏物件）
return function(user, bonusArg)
    local rand = DungeonM.getRandSeed("BROKEN_LAIR") % 100;
    local rand2 = DungeonM.getRandSeed("BROKEN_LAIR");
    local rand3 = DungeonM.getRandSeed("BROKEN_LAIR");

    -- 60%概率：迷宫特色道具，限一次
    -- 40%概率：普通奖励
    local arr1  = {};
    local arr2  = {};
    local classId;
    local dungeonId = CaveHideItemM.getParentDungeonId();
    local class = bonusArg.class;
    local specialBonusCount = CaveHideItemM.getSpecialBonusCount(class);

    if rand < 40 and specialBonusCount <= 0 then
        -- 统计特殊奖励出现次数
        CaveHideItemM.statSpecialBonusCount(class);

        -- 冒险者の森
        if dungeonId == 1 then
            return { { 1, 7285, 3 }, { 1, 7288, 5 }, };
        end

        -- 英雄の村
        if dungeonId == 2 then
            local bonus = {};
            local key;
            local seeds = { rand2, rand3, };

            -- 随机抽取两个元素
            arr1 = { { ["classId"] = 8173, ["ratio"] = 100, }, { ["classId"] = 8174, ["ratio"] = 100, }, { ["classId"] = 8175, ["ratio"] = 100, }, };
            arr2 = fetchElemsBySeeds(arr1, seeds);
            for _, key in pairs(arr2) do
                table.insert(bonus, { 1, key["classId"], 1 });
            end
            return bonus;
        end

        -- 遗落の圣坛
        if dungeonId == 3 then
            classId = FormulaM.invoke("FETCH_BY_RAND", { 7080, 7081, }, rand2);
            return { 1, classId, 1 };
        end

        -- 废弃边陲
        if dungeonId == 4 then
            return { { 1, 7022, 3 }, { 1, 7023, 3 }, { 1, 7024, 3 }, };
        end

        -- 古代竞技场
        if dungeonId == 5 then
            return { 1, 7029, 3 };
        end

        -- 低语の森
        if dungeonId == 6 then
            return { 1, 7278, 3 };
        end

        -- 圣者の塔
        if dungeonId == 7 then
            return { { 1, 7111, 1 }, { 1, 7112, 2 }, };
        end

        -- 砂漠の绿洲
        if dungeonId == 8 then
            return { { 1, 7169, 2 }, { 1, 7176, 1 }, { 1, 7177, 1 }, };
        end

        -- 血腥要塞
        if dungeonId == 9 then
            return { { 1, 8084, 1 }, { 1, 8085, 1 }, { 1, 8086, 1 }, };
        end

        -- 德古拉城堡
        if dungeonId == 10 then
            return { 1, 7242, 1 };
        end

        -- 海贼の港
        if dungeonId == 1001 then
            return { { 1, 8078, 1 }, { 1, 8079, 1 }, { 1, 8080, 1 }, };
        end

        -- 骷髅岛
        if dungeonId == 1002 then
            return { { 1, 7046, 1 }, { 1, 7047, 1 }, };
        end

        -- 阿瓦隆要塞
        if dungeonId == 1004 then
            return { 1, 7522, 3 };
        end

        -- 蒸汽之都
        if dungeonId == 1003 then
            return { { 1, 7564, 1 }, { 1, 7565, 1 }, { 1, 7567, 3 }, };
        end
    else
        local rand1 = DungeonM.getRandSeed("BROKEN_LAIR") % 100;

        if rand1 < 65 then
            arr1 = { { ["amount"] = 2, ["ratio"] = 100, }, { ["amount"] = 3, ["ratio"] = 100, }, };
            local info = fetchElemBySeed(arr1, rand2);

            classId = FormulaM.invoke("CALC_GET_SCROLL_BY_RANK", user, 1);
            return { 1, classId, info["amount"] };
        else
            arr1 = { 7089, };
            arr2 = { 7104, 7105, };
            return { { 1, FormulaM.invoke("FETCH_BY_RAND", arr1, rand2), 1 },
                     { 1, FormulaM.invoke("FETCH_BY_RAND", arr2, rand3), 1 }, };
        end
    end

   return {};
end
